package com.zxy.supplier_system.server.controller

import com.zxy.supplier_system.server.entity.Authority
import com.zxy.supplier_system.server.entity.MarketReturnOrder
import com.zxy.supplier_system.server.service.MarketReturnOrderService
import com.zxy.supplier_system.server.utils.IntIdAndName
import org.springframework.data.domain.Pageable
import org.springframework.data.domain.Slice
import org.springframework.web.bind.annotation.*
import java.time.OffsetDateTime

@RestController
@RequestMapping("markets/{marketId}/returnOrders")
class MarketsReturnOrderController(
    private val marketOrderService: MarketReturnOrderService
) {

    class CreateMarkerReturnOrderRequest(
        val note:String?
    )

    @HasAnyAuthority(Authority.卖场_退货单_下单)
    @PostMapping
    fun createMarketReturnOrder(@PathVariable marketId: Int,request: CreateMarkerReturnOrderRequest):Int{
        return this.marketOrderService.createMarketReturnOrder(marketId,request)
    }

    @HasAnyAuthority(Authority.卖场_退货单_查询)
    @GetMapping
    fun queryMarketReturnOrderInMarket(@PathVariable marketId: Int,pageable: Pageable):Slice<QueryMarketReturnOrderInMarketResponse>{
        return this.marketOrderService.queryMarketReturnOrderInMarket(marketId,pageable)
    }

    data class QueryMarketReturnOrderInMarketResponse(
        val id:Int,
        val createdBy: IntIdAndName,
        val createdDateTime: OffsetDateTime,
        val goodsKindAmount:Int,
        val submittedDateTime: OffsetDateTime?,
        val status:MarketReturnOrder.Status,
    )

    @GetMapping("createdBys", params = ["projection=summary"])
    fun queryOrderCreatedEmployeesByMarketId(@PathVariable marketId: Int):List<IntIdAndName>{
        return this.marketOrderService.queryOrderCreatedEmployeesByMarketId(marketId)
    }



}